import 'package:happy_study/core/constant/constant.dart';
import 'package:sqflite/sqflite.dart';

///参考 https://blog.csdn.net/qq_19979101/article/details/93030803
class DBUtil {
  static late Database database;
  static initDB() async {
    var databasePath = await getDatabasesPath();
    String dbName = Constant.dbName;
    String path = databasePath + dbName;
    database = await openDatabase(path, version: Constant.version);
  }
  static isTableExists(String tableName) async {
    await getCurrentDatabase();
    String sql = "select * from Sqlite_master where type = 'table' and name = '$tableName'";
    var res = await database.rawQuery(sql);
    return res != null && res.isNotEmpty;
  }
  static Future<Database> getCurrentDatabase() async {
    await initDB();
    return database;
  }
  static closeDB() {
    database.close();
  }

}